<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--销售需求单-->
			<view class="detail-item">
				<uni-section title="销售需求单" type="line"></uni-section>
				<view class="detail-content table">
					<ty-table
						:data="tableList"
						:columns="columns"
						:sortable="true"
						:cellClassName="() => 'table-cell'"
						:headerCellClassName="() => 'table-cell'"
						:rowClassName="() => 'table-row'"
						stripe
						border>
						<template v-slot:before="{ row }">
							<view class="table-td-before table-cell">
								<view class="table-td-row">
									销需编号：
									<text class="table-td-text">{{row.number}}</text>
									<text class="detail-text-copy" @click="copyText(row.number)">复制</text>
									<text v-if="checkPermi(['zhouyz:salesmanDemand:list'])" class="detail-text-copy" @click="showPage(row)">查看</text>
								</view>
							</view>
						</template>
						<template v-slot:left="{ row }">
							<view class="table-cell">
								<view class="table-td-row">
									配送仓：
									<text class="table-td-text">{{row.warehouseName}}</text></view>
								<view class="table-td-row">
									分拣仓：
									<text class="table-td-text">{{row.fenjianWarehouseName}}</text></view>
								<view class="table-td-row">
									数量：
									<text class="table-td-text">{{row.products}}</text></view>
							</view>
						</template>
						<template v-slot:right="{ row }">
							<view class="table-cell">
								<view class="table-td-row">
									制单人：
									<text class="table-td-text">{{row.createUserName}}</text>
								</view>
								<view class="table-td-row">
									制单时间：
									<text class="table-td-text">{{row.createTime}}</text>
								</view>
								<view class="table-td-row">
									审核时间：
									<text class="table-td-text">{{row.confirmTime}}</text>
								</view>
							</view>
						</template>
					</ty-table>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { salesmanDemandProductSummaryDetail } from "@/api/erp_api/purchase"
import { copyText, arrText, getDayOfMonth } from '@/utils/ty.js';
import useUserStore from '@/store/modules/user'

	const userStore = useUserStore()
	onLoad(async (option) => {
		if (option.productId) {
			productId.value = option.productId
			getList()
		}
	})
	
	// 数据查询
	const productId = ref('')
	
	// 需求商品
	const columns = ref([
		{ title: '需求信息', key: 'left' },
		{ title: '制单信息', key: 'right', width: '180px' }
	])
	
	const pageNum = ref(1)
	const pageSize = ref(100)
	const total = ref(0)
	const isLoading  = ref(false)
	const tableList = ref([])
	
	const getList = () => {
		const params = {
			pageNum: pageNum.value,
			pageSize: pageSize.value,
			productId: productId.value,
			startTime: `${getDayOfMonth().startTime} 00:00:00`,
			endTime: `${getDayOfMonth().endTime} 23:59:59`
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		salesmanDemandProductSummaryDetail(params).then(res => {
			tableList.value = res.rows || []
			total.value = res.total
			isLoading.value = false
			uni.hideLoading()
	  }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	const showPage = (row) => {
		uni.navigateTo({
			url: `/pages/sale/salesmanDemandDetail?id=${row.id}`
		})
	}
</script>

<style scoped lang="scss">
.detail-text-integral {
	margin-left: 20rpx;
}
.detail-text-banners {
	margin-left: -10rpx;
}
.detail-text-banner {
	margin: 0 10rpx 10rpx;
}
.detail-text-video {
	width: 100%;
	height: 250rpx;
}
</style>
